﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoolERP_Entities;
using CoolERP_DAL;

namespace CoolERP_BLL
{
    public class ZL_WLBLL : BaseBLL<ZL_WL>
    {       
        public ZL_WLBLL() { }

        public List<ZL_WL> GetWL(Dictionary<string, string> dc, string orderExpr, int? pageIndex, int pageSize, out int totalCount)
        {
            var predicate = PredicateExtensions.True<ZL_WL>();
            if (dc.Count > 0)
            {
                if (dc.ContainsKey("WPID") && !string.IsNullOrEmpty(dc["WPID"]))
                {
                    string[] ids = dc["WPID"].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    predicate = predicate.AndEx(t => !ids.Contains(t.ID.ToString()));
                }
                if (dc.ContainsKey("BH") && !string.IsNullOrEmpty(dc["BH"]))
                {
                    predicate = predicate.AndEx(t => t.BH.Contains(dc["BH"]));
                }
                if (dc.ContainsKey("MC") && !string.IsNullOrEmpty(dc["MC"]))
                {
                    predicate = predicate.AndEx(t => t.MC.Contains(dc["MC"]));
                }
                if (dc.ContainsKey("WLLX") && !string.IsNullOrEmpty(dc["WLLX"]))
                {
                    predicate = predicate.AndEx(t => t.LXBH == dc["WLLX"]);
                }
                if (dc.ContainsKey("GYS") && !string.IsNullOrEmpty(dc["GYS"]))
                {
                    Guid id = new Guid(dc["GYS"]);
                    predicate = predicate.AndEx(t => t.GYSID == id);
                }
                if (dc.ContainsKey("SXZBH1") && !string.IsNullOrEmpty(dc["SXZBH1"]))
                {
                    predicate = predicate.AndEx(t => t.SXZBH1 == dc["SXZBH1"]);
                }
                if (dc.ContainsKey("SXZBH2") && !string.IsNullOrEmpty(dc["SXZBH2"]))
                {
                    predicate = predicate.AndEx(t => t.SXZBH2 == dc["SXZBH2"]);
                }
                if (dc.ContainsKey("SXZBH3") && !string.IsNullOrEmpty(dc["SXZBH3"]))
                {
                    predicate = predicate.AndEx(t => t.SXZBH3 == dc["SXZBH3"]);
                }
                if (dc.ContainsKey("SXZBH4") && !string.IsNullOrEmpty(dc["SXZBH4"]))
                {
                    predicate = predicate.AndEx(t => t.SXZBH4 == dc["SXZBH4"]);
                }
                if (dc.ContainsKey("SXZBH5") && !string.IsNullOrEmpty(dc["SXZBH5"]))
                {
                    predicate = predicate.AndEx(t => t.SXZBH5 == dc["SXZBH5"]);
                }
                if (dc.ContainsKey("SXZBH6") && !string.IsNullOrEmpty(dc["SXZBH6"]))
                {
                    predicate = predicate.AndEx(t => t.SXZBH6 == dc["SXZBH6"]);
                }
                if (dc.ContainsKey("SXZBH7") && !string.IsNullOrEmpty(dc["SXZBH7"]))
                {
                    predicate = predicate.AndEx(t => t.SXZBH7 == dc["SXZBH7"]);
                }
                if (dc.ContainsKey("SXZBH8") && !string.IsNullOrEmpty(dc["SXZBH8"]))
                {
                    predicate = predicate.AndEx(t => t.SXZBH8 == dc["SXZBH8"]);
                }
            }
            return base.GetPagerList(predicate.Compile(), orderExpr, pageIndex, pageSize, out totalCount);
        }

        public string GetMaxBH(string BH)
        {
            List<string> bhList = base.GetList(t => t.BH.Contains(BH)).Select(t => t.BH).ToList();
            return bhList.Max();
        }        
    }
}
